package com.fenghongzhang.kuaishou.utils;

import com.fenghongzhang.kuaishou.common.ShuaiFengServerApi;
import com.fenghongzhang.kuaishou.common.XinYIServerApi;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 网络请求工具封装
 */
public class RetrofitManager {

    private RetrofitManager(){}
    private static RetrofitManager retrofitManager = null;

    public synchronized static RetrofitManager getInstance() {
        if(retrofitManager == null){
            retrofitManager =  new RetrofitManager();
        }
        return retrofitManager;
    }
    private Retrofit retrofit;

    private Retrofit shuaiFengRetrofit;
    public Retrofit getRetrofit(){
        if(retrofit == null){
            return  retrofit = new Retrofit.Builder()
                    .client(new OkHttpClient.Builder()
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .baseUrl(XinYIServerApi.BaseUrl)
                    .build();
        }
        return retrofit;
    }


    public Retrofit getShuaiFengServerRetrofit(){
        if(shuaiFengRetrofit == null){
            return  shuaiFengRetrofit = new Retrofit.Builder()
                    .client(new OkHttpClient.Builder()
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .baseUrl(ShuaiFengServerApi.BASE_URL)
                    .build();
        }
        return shuaiFengRetrofit;
    }
}
